﻿package mortal.game.view.signUp.lineOn.item
{
    import com.gengine.core.*;
    import com.gengine.core.frame.*;
    import com.mui.controls.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.game.mvc.*;
    import mortal.game.view.common.*;

    public class LineOnRollBase extends GSprite
    {
        protected var _timer:FrameTimer;
        protected var _container:GSprite;
        protected var _maskSp:GSprite;
        protected var _renderArr:Array;
        protected var _speed:Number = 2;
        protected var _cellHei:Number = 45;
        protected var _hasMove:Number = 0;
        protected var _moveCellNum:int = 0;
        protected var _synChildArr:Array;
        protected var _totalHei:int = 100;
        private var _setTime:uint = 0;

        public function LineOnRollBase()
        {
            this._container = new GSprite();
            this._maskSp = new GSprite();
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            this._container = UIFactory.getUICompoment(GSprite);
            this.addChild(this._container);
            this._maskSp = UIFactory.getUICompoment(GSprite);
            this.addChild(this._maskSp);
            this._container.mask = this._maskSp;
            this.setMask(this._container.x, this._container.y, 50, 20);
            var _loc_1:* = this.getTimeInterval();
            this._timer = new FrameTimer(_loc_1);
            this._timer.addListener(TimerType.ENTERFRAME, this.onTimeHd);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._container.dispose(param1);
            this._maskSp.dispose(param1);
            this._maskSp = null;
            this._container = null;
            if (this._timer)
            {
                this._timer.stop();
                this._timer.dispose(param1);
            }
            this._timer = null;
            if (this._setTime != 0)
            {
                clearTimeout(this._setTime);
            }
            this._setTime = 0;
            this.disposeRends();
            this._synChildArr = null;
            return;
        }// end function

        protected function getTimeInterval() : int
        {
            return 1;
        }// end function

        public function getRenders(param1:Array) : void
        {
            this._totalHei = (param1.length - 1) * this._cellHei * -1;
            return;
        }// end function

        protected function disposeRends() : void
        {
            var _loc_2:IDispose = null;
            if (this._renderArr == null)
            {
                return;
            }
            var _loc_1:int = 0;
            while (_loc_1 < this._renderArr.length)
            {
                
                _loc_2 = this._renderArr[_loc_1] as IDispose;
                if (_loc_2)
                {
                    _loc_2.dispose();
                }
                _loc_1++;
            }
            this._renderArr = null;
            return;
        }// end function

        protected function setMask(param1:int, param2:int, param3:int, param4:int) : void
        {
            this._maskSp.graphics.clear();
            this._maskSp.graphics.beginFill(0);
            this._maskSp.graphics.drawRect(0, 0, param3, param4);
            this._maskSp.x = param1;
            this._maskSp.y = param2;
            this.addChild(this._maskSp);
            return;
        }// end function

        protected function onTimeHd(param1:FrameTimer) : void
        {
            var _loc_2:Number = NaN;
            var _loc_3:int = 0;
            this._container.y = this._container.y + this._speed;
            this._hasMove = this._hasMove + this._speed;
            _loc_2 = this._container.y / this._totalHei;
            this.synChild(_loc_2);
            if (this._hasMove >= this._cellHei)
            {
                _loc_3 = this._hasMove - this._cellHei;
                this._container.y = this._container.y - _loc_3;
                _loc_2 = this._container.y / this._totalHei;
                this.synChild(_loc_2);
                this._hasMove = 0;
                var _loc_4:String = this;
                var _loc_5:* = this._moveCellNum + 1;
                _loc_4._moveCellNum = _loc_5;
                this._timer.stop();
                if (this._moveCellNum >= (this._renderArr.length - 1))
                {
                    this.dispatchEvent(new Event(EventName.LineOnCellRollComplete));
                }
                else
                {
                    this._setTime = setTimeout(this.star, 500);
                }
            }
            return;
        }// end function

        protected function synChild(param1:Number) : void
        {
            var _loc_3:LineOnRollBase = null;
            if (this._synChildArr == null)
            {
                return;
            }
            var _loc_2:int = 0;
            while (_loc_2 < this._synChildArr.length)
            {
                
                _loc_3 = this._synChildArr[_loc_2];
                _loc_3.synPos(param1);
                _loc_2++;
            }
            return;
        }// end function

        public function addSynChild(param1:LineOnRollBase) : void
        {
            if (this._synChildArr == null)
            {
                this._synChildArr = [];
            }
            if (this._synChildArr.indexOf(param1) == -1)
            {
                this._synChildArr.push(param1);
            }
            return;
        }// end function

        public function synPos(param1:Number) : void
        {
            this._container.y = int(param1 * this._totalHei);
            return;
        }// end function

        public function star() : void
        {
            clearTimeout(this._setTime);
            this._setTime = 0;
            this._timer.start();
            return;
        }// end function

        public function stop() : void
        {
            this._timer.stop();
            return;
        }// end function

        public function reset() : void
        {
            this._container.y = 0;
            this._timer.stop();
            this._hasMove = 0;
            this._moveCellNum = 0;
            return;
        }// end function

    }
}
